﻿Public Class frmproducteditor

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Cmd.Parameters("@name") = Me.txtname.Text
        Cmd.Parameters("@code") = Me.txtcode.Text
        Cmd.Parameters("@cat") = Me.txtcat.Text
        Cmd.Parameters("@price") = Me.txtprice.Text
        Cmd.Parameters("@miniprice") = Me.txtminiprice.Text
        If Me.txtid.Text = "" Then
            Cmd.ExecuteNonQuery("INSERT INTO Product VALUES(@code,@name,@cat,@price,@miniprice,1);")
        Else
            Cmd.Parameters("@Id") = txtid.Text
            Cmd.ExecuteNonQuery("UPDATE Product SET ProductCode=@code,ProductName=@name,CategoryId=@cat,Price=@price,MinimumPrice=-@miniprice WHERE ProductId=@Id")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK
        product.loaddata()
        Me.Close()
    End Sub

    Public Sub Loadtype()
        Dim dr = Cmd.ExecuteDataReader("SELECT * FROM Category")
        Dim dt As New DataTable()
        dt.Load(dr)
        dr.Close()

        ComboBox1.DisplayMember = "CategoryName"
        ComboBox1.ValueMember = "CategoryId"
        ComboBox1.DataSource = dt
    End Sub

    Private Sub frmproducteditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Loadtype()
    End Sub
End Class
